<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API登录示例</title>
    <style type="text/css">
        .login {
            width: 230px;
            height: 300px;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .login>button {
            margin-top: 10px;
            width: 50PX;
            margin-left: 105px;
        }
    </style>
    <script src="./witcloud-sdk-1.0.0.min.js"></script>
</head>

<body>
    <div class="login">
        <div><span>账号：</span><input type="text" name="appId" /></div>
        <div><span>密码：</span><input type="password" name="appSecret" /></div>
        <button onclick="login()">登录</button>
    </div>

    <script>

        // 登录方法：点击后获得文本框内容,向后台服务器发起登录请求
        function login() {
            var param = {};
            param.appId = document.getElementsByName("appId")[0].value
            param.appSecret = document.getElementsByName("appSecret")[0].value

            witCloudApi.loginApi.login(param).then((res) => {
                if (res.success) {
                    alert('登录成功')
                } else {
                    // 如果登录失败请按照 res.message 的返回信息修正错误
                    alert('登录失败：' + res.message)
                }
            }).catch((err) => {
                alert('登录错误：' + err.message)
            })
        }
    </script>
</body>

</html>